package cn.jinjimi.app.custom.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import cn.jinjimi.app.R;
import cn.jinjimi.app.bean.Constants;
import cn.jinjimi.app.main.extend.ToolBarCommonActivity;
import cn.jinjimi.app.main.fragment.CardFragment;

/**
 * 卡片列表
 * 生日卡片
 * 节日卡片
 * Created by Jinsen on 2015/5/14.
 */
public class CardListActivity extends ToolBarCommonActivity {
    public static final int LOAD_UNKNOWN = -1;
    public static final int LOAD_BIRTHDAY = 0;
    public static final int LOAD_HOLIDAY_WITH_ID = 1;
    public static final int LOAD_SCENE_WITH_ID = 2;
    int mLoadType = LOAD_BIRTHDAY;
    int mCardType = Constants.REMIND_TYPE_BIRTHDAY;
    String mTitle = null;
    String mCustomId = null;

    public static void launch(Context startActivity) {
        if (startActivity == null)
            return;
        Intent intent = new Intent(startActivity, CardListActivity.class);
        startActivity.startActivity(intent);
    }

    @Override
    protected void beforeInitView() {
        setContentView(R.layout.activity_bless_grid_layout);
    }

    @Override
    protected void initial() {
        mTitle = getIntent().getStringExtra("title");
        mLoadType = getIntent().getIntExtra("loadType", LOAD_UNKNOWN);
        mCardType = getIntent().getIntExtra("cardType", Constants.REMIND_TYPE_BIRTHDAY);
        //此时是从路由过来，加载生日或某一个节日，生日id(默认0)或节日id从Intent中的id获取，并设置加载类型为加载节日
        if (mLoadType == LOAD_UNKNOWN) {
            String hid = getIntent().getStringExtra("id");
            try {
                int id = Integer.valueOf(hid);
                mCardType = id > 0 ? id : mCardType;
            } catch (Exception e) {
            }
            mLoadType = LOAD_HOLIDAY_WITH_ID;
        }

        mCustomId = getIntent().getStringExtra("customId");
        setTitle(R.string.remind_default_title);

        CardFragment cardFm = new CardFragment();
        cardFm.setCardTypeId(mCardType);
        if (mLoadType == LOAD_BIRTHDAY) {
            cardFm.setType(CardFragment.LoadType.BIRTHDAY);
        } else if (mLoadType == LOAD_HOLIDAY_WITH_ID) {
            cardFm.setType(CardFragment.LoadType.HOLIDAY_WITH_ID);
        } else if (mLoadType == LOAD_SCENE_WITH_ID) {
            cardFm.setType(CardFragment.LoadType.SCENE_WITH_ID);
        }
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fl_container, cardFm);
        ft.commit();
    }

}
